package com.gw.vip.server.tool;

import com.gw.vip.server.po.Account;
import com.gw.vip.server.po.SysCapitalType;
import com.gw.vip.server.service.dao_service.AccountService;
import com.gw.vip.server.service.dao_service.SysCapitalTypeService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Comparator;
import java.util.List;

/**
 * @author GW 光武
 * @description
 * @since 2023-03-18
 */
@Service
@Slf4j
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
public class MainServiceTool {

    private final AccountService accountService;
    private final SysCapitalTypeService sysCapitalTypeService;

    /**
     * 查找可以扣款的主账户
     * @param userId
     * @return
     */
    public List<Account> mainAvaAcc(String userId) {
        return accountService.mainAvaAcc(userId);
    }

    /**
     * 帐户排序
     * @param accountList
     * @return
     */
    public void sortAcc(List<Account> accountList) {
        List<SysCapitalType> sysCapitalTypeList = sysCapitalTypeService.list();
        accountList.sort(Comparator.comparing(userAccount -> sysCapitalTypeService.getPayOrder(sysCapitalTypeList, userAccount.getCapitalId())));
    }
}
